package com.springboot.admin.acutuator.health;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/************************************************************************
 *
 *    Copyright  Copyright 2021 Google Inc.
 *    File Name: MyComHealthIndicator
 *    Description: 健康检查
 *
 *    Version: V1.0
 *    Author: Fuc
 *    Create Time: 2021-01-11
 *
 *************************************************************************/

@Component
public class MyComHealthIndicator extends AbstractHealthIndicator {

  /**
   * 真实的检查方法
   *
   * @param builder
   * @throws Exception
   */
  @Override
  protected void doHealthCheck(Health.Builder builder) throws Exception {
    // mongodb。  获取连接进行测试
    Map<String, Object> map = new HashMap<>(2);
    // 检查完成
    if (1 == 1) {
      //            builder.up(); //健康
      builder.status(Status.UP);
      map.put("count", 1);
      map.put("ms", 100);
    } else {
      //            builder.down();
      builder.status(Status.OUT_OF_SERVICE);
      map.put("err", "连接超时");
      map.put("ms", 3000);
    }

    builder.withDetail("code", 100).withDetails(map);
  }

}
